package com.wiscofile.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

import com.wiscofile.pojo.WiscoDataEquipIntroduction;

/**
 * A data access object (DAO) providing persistence and search support for
 * WiscoDataEquipIntroduction entities. Transaction control of the save(),
 * update() and delete() operations can directly support Spring
 * container-managed transactions or they can be augmented to handle
 * user-managed Spring transactions. Each of these methods provides additional
 * information for how to configure it for the desired type of transaction
 * control.
 * 
 * @see com.wiscofile.pojo.WiscoDataEquipIntroduction
 * @author MyEclipse Persistence Tools
 */

public class WiscoDataEquipIntroductionDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(WiscoDataEquipIntroductionDAO.class);
	

	public boolean save(WiscoDataEquipIntroduction transientInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.save(transientInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			re.printStackTrace();
			return false;
		}
	}
	
	public boolean update(WiscoDataEquipIntroduction transientInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.clear();
			session.update(transientInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			re.printStackTrace();
			return false;
		}
	}

	public boolean delete(WiscoDataEquipIntroduction persistentInstance) {
		try {
			Session session = getSession();
			Transaction tra = session.beginTransaction();
			session.delete(persistentInstance);
			tra.commit();
			session.close();
			return true;
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			re.printStackTrace();
			return false;
		}
	}

	public WiscoDataEquipIntroduction findById(java.lang.String id) {
		try {
			Session session = getSession();
			WiscoDataEquipIntroduction instance = (WiscoDataEquipIntroduction) session
					.get("com.wiscofile.pojo.WiscoDataEquipIntroduction", id);
			session.close();
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			re.printStackTrace();
			throw re;
		}
	}

	

	public List findAll(int first,int pagesize) {
		try {
			Session session = getSession();
			String queryString = "from WiscoDataEquipIntroduction";
			Query queryObject = session.createQuery(queryString);
			queryObject.setFirstResult(first);
			queryObject.setMaxResults(pagesize);
			List list = queryObject.list();
			session.close();
			return list;
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			re.printStackTrace();
			throw re;
		}
	}
	
	public int countAll() {
		try {
			Session session = getSession();
			String queryString = " select count(w) from WiscoDataEquipIntroduction w";
			Query queryObject = session.createQuery(queryString);
			Long count = (Long) queryObject.list().get(0);
			session.close();
			return count.intValue();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			re.printStackTrace();
			throw re;
		}
	}
	
	public WiscoDataEquipIntroduction merge(
			WiscoDataEquipIntroduction detachedInstance) {
		log.debug("merging WiscoDataEquipIntroduction instance");
		try {
			WiscoDataEquipIntroduction result = (WiscoDataEquipIntroduction) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(WiscoDataEquipIntroduction instance) {
		log.debug("attaching dirty WiscoDataEquipIntroduction instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(WiscoDataEquipIntroduction instance) {
		log.debug("attaching clean WiscoDataEquipIntroduction instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}